/************************************************************************************************************
 * @attention
 *
 * Firmware Disclaimer Information
 *
 * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the
 *    code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the
 *    proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and
 *    other intellectual property laws.
 *
 * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the
 *    code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties
 *    other than HOLTEK and the customer.
 *
 * 3. The program technical documentation, including the code, is provided "as is" and for customer reference
 *    only. After delivery by HOLTEK, the customer shall use the program technical documentation, including
 *    the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including
 *    the warranties of merchantability, satisfactory quality and fitness for a particular purpose.
 *
 * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2>
 ************************************************************************************************************/
// Generated by HT32CodeConfig V1.1.3 Build 240823
//-----------------------------------------------------------------------------
#include "bsp_system.h"
uint8_t one_w[32] = {0};
uint8_t two_w[32] = {0};
uint8_t three_w[32] = {0};
uint8_t four_w[32] = {0};
uint8_t one_t[32] = {0};
uint8_t two_t[32] = {0};
uint8_t three_t[32] = {0};
uint8_t four_t[32] = {0};
float mq_value = 0.0f;
//-----------------------------------------------------------------------------
int main(void)
{
#if (HTCFG_STACK_USAGE_ANALYSIS == 1)
	/* !!! NOTICE !!!
	   Please update the Keil HT32 PACK and HT32 Firmware Library to the latest version to make sure the
	   Stack Usage Analysis function works properly.
	*/
	/*
	  Set HTCFG_STACK_USAGE_ANALYSIS as 1 in the "ht32xxxxxx_conf.h" to enable Stack Usage Analysis feature.
	  This feature is only applicable to the Keil MDK-ARM. Please call the "StackUsageAnalysisInit()" function
	  in the begin of the "main()".
	  The "StackUsageAnalysisInit()" parameter shall be the start address of the vector table.
	  Under Keil Debug mode, tick "View > Watch Window > HT32 Stack Usage Analysis" to show the stack usage
	  information. Those information is only valid a  fter calling "StackUsageAnalysisInit()" function.
	*/
	StackUsageAnalysisInit(0);
#endif
//uint8_t ch[2][2][31] = {		
//    {							
//        {"hello"},  // ch[0][0]	
//        {"world"}   // ch[0][1]	
//    },	
//    {
//        {"hh"},     // ch[1][0]
//        {"ww"}      // ch[1][1]
//    }
//};
	GPIO_Configuration();
	BFTM0_Configuration();
	ADC_Configuration();
	SPI1_Configuration();
	UART0_Configuration();
	UART1_Configuration();
	USART0_Init();
	USART1_Configuration();
	sim800l_init();
	//sim800l_dial();
	wifi_init();

	LCD_Initcm();
	LCD_LED_SET;
	LCD_RST_SET;
	LCD_Clearcm(WHITE);
	POINT_COLOR = RED;
	Gui_Drawbmp16(0, 2, (uint8_t *)gImage_WeiZ);
	Show_Str(40, 5, BLACK, WHITE, (uint8_t *)"位置", 24, 0);
	LCD_ShowString(90, 7, 16, (uint8_t *)":", 0);
	Show_Str(107, 5, BLACK, WHITE, city_data[0], 24, 0);
	//LCD_ShowString(148,67,16,(uint8_t *)"-",0);
	Show_Str(160, 5, BLACK, WHITE, city_data[1], 24, 0);


	Gui_Drawbmp16(0, 50, (uint8_t *)gImage_TQ);
	Show_Str(40, 55, BLACK, WHITE, (uint8_t *)"天气", 24, 0);
	LCD_ShowString(90,60,16,(uint8_t *)":",0);
	
	Show_Str(100, 65, BLACK, WHITE, (uint8_t *)"日间", 24, 0);
	LCD_ShowString(148,67,16,(uint8_t *)":",0);
	//Show_Str(155, 65, BLACK, WHITE, weather_data[0][2], 24, 0);
	
	Show_Str(100, 95, BLACK, WHITE, (uint8_t *)"夜间", 24, 0);
	LCD_ShowString(148,98,16,(uint8_t *)":",0);
	Show_Str(155, 97, BLACK, WHITE, weather_data[0][3], 24, 0);
	
	
	Gui_Drawbmp16(0, 135, (uint8_t *)gImage_Rli);
	Show_Str(40, 140, BLACK, WHITE, (uint8_t *)"日期", 24, 0);
	LCD_ShowString(90,143,16,(uint8_t *)":",0);
	Show_Str(120, 140, BLACK, WHITE, weather_data[0][0], 24, 0);
	Show_Str(120, 166, BLACK, WHITE, (uint8_t *)"星期", 24, 0);
	Show_Str(178, 170, BLACK, WHITE, weather_data[0][1], 32, 0);

	Gui_Drawbmp16(0, 200, (uint8_t *)gImage_T);
	Show_Str(40, 205, BLACK, WHITE, (uint8_t *)"温度", 24, 0);
	LCD_ShowString(90,207,16,(uint8_t *)":",0);
	
	Show_Str(100, 215, BLACK, WHITE, (uint8_t *)"日间", 24, 0);
	LCD_ShowString(148,217,16,(uint8_t *)":",0);
	Show_Str(160, 218, BLACK, WHITE, weather_data[0][4], 24, 0);
	
	Show_Str(100, 245, BLACK, WHITE, (uint8_t *)"夜间", 24, 0);
	LCD_ShowString(148,248,16,(uint8_t *)":",0);
	Show_Str(160, 250, BLACK, WHITE, weather_data[0][5], 24, 0);

	Gui_Drawbmp16(0, 280, (uint8_t *)gImage_co);
	Show_Str(40, 283, BLACK, WHITE, (uint8_t *)"一氧化碳", 24, 0);
	LCD_ShowString(140, 286, 16, (uint8_t *)":", 0);
	memcpy(one_w,weather_data[0][2],32);
	memcpy(two_w,weather_data[1][2],32);
	memcpy(three_w,weather_data[2][2],32);
	memcpy(four_w,weather_data[3][2],32);
	memcpy(one_t,weather_data[0][4],32);
	memcpy(two_t,weather_data[1][4],32);
	memcpy(three_t,weather_data[2][4],32);
	memcpy(four_t,weather_data[3][4],32);
	while (1)
	{
		if (HT_CKCU->APBCCR1 & (1 << 4))
			WDT_Restart();
		// SPI1_test();   //Can be removed
		key_proc();
		buzz_proc();
		mq_value = adc_proc();
		LCD_ShowNum(150, 288, mq_value, 2, 16);
		
//	LCD_ShowNum(150, 55, strlen(weather_data[0][4]), 2, 16);
//		
		
		wifi_data_issued();
	}
}
